package mchecca.view;

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import mchecca.controller.LinesController;
import mchecca.model.DecisionLinesEvent;

/**
 * Main boundary form for DecisionLines.
 * <p>
 * This main GUI element has three main components
 * <ol>
 * 	<li>Choices panel where user enters their unique choices</li>
 * 	<li>{@link LinesCanvas} where user adds edges by clicking between 2 {@link mchecca.model.Line}s</li>
 * 	<li>Decisions panel where the final prioritized list of choices are shown</li>
 * </ol>
 * @author Michael Checca
 */
public class DecisionLinesForm extends JFrame {
	/** Serialized version UID for DecisionLinesForm */
	private static final long serialVersionUID = 3127326749261075841L;
	/** JPanel contentPane to host all controls */
	JPanel contentPane;
	/** Panel for showing final prioritized list of choices */
	JPanel pnlDecisions;
	/** Canvas for drawing and manipulating lines and edges */
	LinesCanvas linesCanvas;
	/** JPanel for showing choices text boxes */
	JPanel pnlChoices;
	/** Label for showing number of edges remaining */
	JLabel lblInformativeMessage;
	/** Label for showing error messages */
	JLabel lblErrorMessage;

	/**
	 * Create the main {@link DecisionLinesForm}.
	 * <p>
	 * Creates the main GUI and all components needed for the {@link DecisionLinesEvent}.
	 * @param dlEvent {@link DecisionLinesEvent} event to model in the GUI
	 */
	public DecisionLinesForm(DecisionLinesEvent dlEvent) {
		int width=800, height=500;
		setTitle("DecisionLines");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(200, 100, width, height);
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		pnlChoices = new JPanel();
		pnlChoices.setBounds(5, 5, 785, 50);
		contentPane.add(pnlChoices);

		linesCanvas = new LinesCanvas(this, dlEvent);
		linesCanvas.setBounds(5, 60, 785, height - (60 + 75));
		linesCanvas.setBackground(Color.white);
		linesCanvas.setEnabled(false);
		contentPane.add(linesCanvas);

		pnlDecisions = new JPanel();
		pnlDecisions.setBounds(linesCanvas.getBounds());
		pnlDecisions.add("lblDecisions", new JLabel("Prioritized Choices"));
		pnlDecisions.setVisible(false);
		contentPane.add(pnlDecisions);

		lblInformativeMessage = new JLabel("Please enter all choices to begin");
		lblInformativeMessage.setBounds(5, height - 50, 300, 15);
		lblInformativeMessage.setBackground(Color.white);
		contentPane.add(lblInformativeMessage);

		lblErrorMessage = new JLabel();
		lblErrorMessage.setBounds(450, height - 50, 300, 15);
		lblErrorMessage.setForeground(Color.red);
		contentPane.add(lblErrorMessage);

		LinesController linesController = new LinesController(this, dlEvent);
		linesCanvas.addMouseListener(linesController);
	}

	/**
	 * Canvas containing the lines and edges.
	 * @return {@link LinesCanvas} for drawing edges
	 */
	public LinesCanvas getLinesCanvas() {
		return this.linesCanvas;
	}

	/**
	 * Panel containing JTextField for choices.
	 * @return {@link JPanel} for storing choice text boxes
	 */
	public JPanel getChoicesPanel() {
		return pnlChoices;
	}

	/**
	 * Panel containing the prioritized decision list.
	 * @return {@link JPanel} for showing the final decisions
	 */
	public JPanel getDecisionsPanel () {
		return pnlDecisions;
	}

	/**
	 * Label containing information messages.
	 * @return {@link JLabel} for showing informative messages
	 */
	public JLabel getInformativeMessage() {
		return lblInformativeMessage;
	}

	/**
	 * Label containing information on errors
	 * @return {@link JLabel} for showing errors
	 * */
	public JLabel getErrorLabel() {
		return lblErrorMessage;
	}
}
